<template>
  <div id="app">
		<router-view v-if="!$route.meta.keepalive"/>
		<keep-alive>
				<router-view v-if="$route.meta.keepalive"/>
		</keep-alive>
  </div>
</template>

<script>
  export default {
    data() {
      return {}
    },
    mounted() {
      window.addEventListener("message", this.handleMessage);
    },
    watch: {
        $route(to, from) {
        //   debugger;
			if (window._czc) {
				var location = window.location
				var content_url = location.pathname + location.hash
				var referer_url = '/'
				window._czc.push(['_trackPageview', content_url, referer_url])    
			}
		
        }
    },
    methods: {
      handleMessage() {
           if (!event.data) return;
            let rawData = event.data;
            if (typeof rawData !== "string") {
                return;
               
            }
            let data = JSON.parse(rawData);
            if (data.nativeEvent !== 'loadUrl')
              return;
           
            let routeUrl = data.data.uri.substr(window.location.origin.length)
            this.$router.push(routeUrl)
      }
    }

  }
</script>

<style>

</style>